package mao.thinkinjava.io;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

public class DirList {
    //final可以不写，但是也不能进行修改，否则会报错
    public static FilenameFilter filter(final String reg){
        return new FilenameFilter() {
            private Pattern pattern = Pattern.compile(reg);
            @Override
            public boolean accept(File dir, String name) {
                return pattern.matcher(name).matches();
            }
        };
    }

    public static void main(String[] args) {
        File file =new File("C:\\Users\\xk1008\\IdeaProjects\\untitled\\src\\com\\mao");
        String[] list = file.list(filter(".*think.*"));
        for (int i = 0; i < list.length; i++) {
            System.out.println(list[i]);
        }
    }
}
